package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RegistLevel;
import com.ruoyi.system.service.IRegistLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 挂号级别Controller
 *
 * @author ruoyi
 * @date 2023-07-04
 */
@Api(tags = "挂号级别模块")
@RestController
@RequestMapping("/system/RegistLevel")
public class RegistLevelController extends BaseController {
    @Autowired
    private IRegistLevelService registLevelService;

    /**
     * 查询挂号级别列表
     */
    @ApiOperation(value = "查询挂号级别列表")
    @PreAuthorize("@ss.hasPermi('system:RegistLevel:list')")
    @GetMapping("/list")
    public Page<RegistLevel> list(RegistLevel entity, Page<RegistLevel> page) {

        LambdaQueryWrapper<RegistLevel> lambdaQueryWrapper = new LambdaQueryWrapper<RegistLevel>();
        return registLevelService.page(page, lambdaQueryWrapper);
    }

    /**
     * 导出挂号级别列表
     */
    @ApiOperation(value = "导出挂号级别列表")
    @PreAuthorize("@ss.hasPermi('system:RegistLevel:export')")
    @Log(title = "挂号级别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RegistLevel registLevel) {
        LambdaQueryWrapper<RegistLevel> queryWrapper = new LambdaQueryWrapper<>();
        List<RegistLevel> list = registLevelService.list(queryWrapper);
        ExcelUtil<RegistLevel> util = new ExcelUtil<RegistLevel>(RegistLevel.class);
        util.exportExcel(response, list, "挂号级别数据");
    }


    /**
     * 获取挂号级别详细信息
     */
    @ApiOperation(value = "获取挂号级别详细信息")
    @PreAuthorize("@ss.hasPermi('system:RegistLevel:query')")
    @GetMapping(value = "/{Id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(registLevelService.getById(id));
    }

    /**
     * 新增挂号级别
     */
    @ApiOperation(value = "新增挂号级别")
    @PreAuthorize("@ss.hasPermi('system:RegistLevel:add')")
    @Log(title = "挂号级别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RegistLevel registLevel) {
        return toAjax(registLevelService.save(registLevel));
    }

    /**
     * 修改挂号级别
     */
    @ApiOperation(value = "修改挂号级别")
    @PreAuthorize("@ss.hasPermi('system:RegistLevel:edit')")
    @Log(title = "挂号级别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RegistLevel registLevel) {
        return toAjax(registLevelService.updateById(registLevel));
    }


    /**
     * 删除挂号级别
     */
    @ApiOperation(value = "删除挂号级别")
    @PreAuthorize("@ss.hasPermi('system:RegistLevel:remove')")
    @Log(title = "挂号级别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{Ids}")
    public AjaxResult remove(@PathVariable Long[] Ids) {
        return toAjax(registLevelService.removeBatchByIds(Arrays.asList(Ids)));
    }
}
